//
//  NRWCarMultipleChooseCarCellTableViewCell.m
//  New_Runway
//
//  Created by NewLife on 2018/3/8.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWCarMultipleChooseCarCell.h"
#import "NRWCarListsModel.h"

@implementation NRWCarMultipleChooseCarCell
{
    UIButton *_selectBtn;
    UIImageView *_carImageView;
    UILabel *_carNameLabel;
    UILabel *_carPriceLabel;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self setupUI];
        
        [self layoutUI];
        
        self.separatorInset = UIEdgeInsetsZero;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)setModel:(Result *)model {
    
    _model = model;
    
    [_carImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ImageApi,model.carImageUrl]] placeholderImage:getImageFromName(@"tu")];
    
    _carNameLabel.text = model.carTitle;
    
    _carPriceLabel.text = [NSString stringWithFormat:@"¥%.2f万",model.carRetailPrice];
}

- (void)setSelectedState:(BOOL)selectedState {
    
    _selectedState = selectedState;
    
    _selectBtn.selected = selectedState;
}

- (void)setupUI {
    
    _selectBtn = DPButton()
    .setNormalImage(getImageFromName(@"circle"))
    .setSelectedImage(getImageFromName(@"hook"))
    .setUserInteractionEnabled(NO);
//    .addClickAction(self, @selector(selectBtnDidClick:));
    
    _carImageView = [[UIImageView alloc] init];
    _carImageView.backgroundColor = [UIColor whiteColor];
    _carImageView.opaque = YES;
    _carImageView.clipsToBounds = YES;
    _carImageView.contentMode = UIViewContentModeScaleAspectFill;
    
    _carNameLabel = [[UILabel alloc] init];
    _carNameLabel.font = kPingFangRegular12();
    _carNameLabel.textColor = [UIColor colorFromHexCode:@"#323232"];
    _carNameLabel.numberOfLines = 2;
    _carNameLabel.backgroundColor = [UIColor colorFromHexCode:@"#ffffff"];
    _carNameLabel.opaque = YES;
    
    _carPriceLabel = [[UILabel alloc] init];
    _carPriceLabel.font = kPingFangRegular13();
    _carPriceLabel.textColor = [UIColor colorFromHexCode:@"#ff6816"];
    _carPriceLabel.backgroundColor = [UIColor colorFromHexCode:@"#ffffff"];
    _carPriceLabel.opaque = YES;
    
    [self.contentView addSubview:_selectBtn];
    [self.contentView addSubview:_carImageView];
    [self.contentView addSubview:_carNameLabel];
    [self.contentView addSubview:_carPriceLabel];
}

- (void)layoutUI {
    
    [_selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.equalTo(@40);
        make.centerY.equalTo(self.contentView.mas_centerY);
        make.left.equalTo(self.contentView.mas_left);
    }];
    
    [_carImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@90);
        make.height.equalTo(@60);
        make.left.equalTo(_selectBtn.mas_right);
        make.centerY.equalTo(_selectBtn.mas_centerY);
    }];
    
    [_carNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_carImageView.mas_top);
        make.left.equalTo(_carImageView.mas_right).offset(10);
        make.right.equalTo(self.contentView.mas_right).offset(-20);
    }];
    
    [_carPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_carImageView.mas_bottom);
        make.left.equalTo(_carNameLabel.mas_left);
    }];
}

- (void)selectBtnDidClick:(UIButton *)sender {
    
    
}


@end
